﻿/*
Copyright (c) 2008 Martin Legris

Permission is hereby granted, free of charge, to any person obtaining a copy of this 
software and associated documentation files (the "Software"), to deal in the Software 
without restriction, including without limitation the rights to use, copy, modify, 
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
permit persons to whom the Software is furnished to do so, subject to the following 
conditions:

The above copyright notice and this permission notice shall be included in all copies 
or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ignore
*/
package newcommerce.lastfm.api.data 
{
	import newcommerce.lastfm.api.feeds.LFMImageFeed;
	
	/**
	 * ...
	 * @author Martin Legris ( http://blog.martinlegris.com )
	 */
	public class LFMEventData 
	{
		protected var _id:Number;
		protected var _artists:Array;
		protected var _headliner:String;
		protected var _venue:LFMVenueData;
		protected var _startDate:Date;
		protected var _startTime:String;
		protected var _description:String;
		protected var _attendance:Number;
		protected var _reviews:Number;
		protected var _images:LFMImageFeed;
		protected var _tag:String;
		protected var _url:String;
		
		public function get id():Number { return _id; }
		public function get artists():Array { return _artists; }
		public function get headliner():String { return _headliner; }
		public function get venue():LFMVenueData { return _venue; }
		public function get startDate():Date { return _startDate; }
		public function get startTime():String { return _startTime; }
		public function get description():String { return _description; }
		public function get attendance():Number { return _attendance; }
		public function get reviews():Number { return _reviews; }		
		public function get images():LFMImageFeed { return _images; }
		public function get tag():String { return _tag; }
		public function get url():String { return _url; }
		
		public function LFMEventData() 
		{
			
		}
		
		public static function fromXML(xml:XML):LFMEventData
		{
			var data:LFMEventData = new LFMEventData();
			data._id = parseInt(xml.id[0].toString());
			
			data._artists = [];
			for (var i:Number = 0; i < xml.artists.artist.length(); i++)
				data._artists.push(xml.artists.artist[i].toString());
				
			data._headliner = xml.artists.headliner.toString();
			
			data._venue = LFMVenueData.fromXML(xml.venue[0]);
			data._startDate = new Date(Date.parse(xml.startDate.toString));
			data._startTime = xml.startTime.toString();
			data._description = xml.description.toString();
			data._attendance = parseInt(xml.attendance.toString());
			data._reviews = parseInt(xml.reviews.toString());
			data._tag = xml.tag.toString();
			data._url = xml.url.toString();
			data._images = new LFMImageFeed(xml.image);
			
			return data;
		}
	}
}